// 引入store
import store from '@/store'
function All() {}
All.prototype = {
    operatorToString(config) {
        if (!config) return ''
        const { users, roles, departs } = config
        const parts = []
        if (departs?.length) parts.push(`部门：${departs.map(item => store.state.flow.operatorMapping.depart[item]).join(',')}`)
        if (users?.length) parts.push(`用户：${users.map(item => store.state.flow.operatorMapping.user[item]).join(',')}`)
        if (roles?.length) parts.push(`角色：${roles.map(item => store.state.flow.operatorMapping.role[item]).join(',')}`)
        
        return parts.length? parts.join('；') : '';
    },
    removeEle(arr, elem, key = 'id') {
        var includesIndex;
        arr.map((item, index) => {
            if (item[key] == elem[key]) {
                includesIndex = index
            }
        });
        arr.splice(includesIndex, 1);
    },
    setApproverStr(nodeConfig) {
        const {users, roles, departs} = nodeConfig
        const operatorLength = users?.length + roles?.length + departs?.length
        if (nodeConfig.assigneeType == 'user' || nodeConfig.assigneeType == 'role' || nodeConfig.assigneeType == 'depart') {
            if (operatorLength > 0) {
                let prefix = nodeConfig.multi == 'single' ? '或签' : '会签'
                return this.operatorToString(nodeConfig) + prefix
            } else {
                return ""
            }
        } else if (nodeConfig.assigneeType == 'self') {
            return "发起人自己"
        } else if (nodeConfig.assigneeType =='autoPass') {
            return "系统自动通过"
        } else if (nodeConfig.assigneeType =='autoRefuse') {
            return "系统自动拒绝"
        }
    },
    setCopyerStr(nodeConfig) {
        const {users, roles, departs} = nodeConfig
        const operatorLength = users?.length + roles?.length + departs?.length
        if (nodeConfig.assigneeType == 'user' || nodeConfig.assigneeType == 'role' || nodeConfig.assigneeType == 'depart') {
            if (operatorLength > 0) {
                return this.operatorToString(nodeConfig)
            } else {
                return ""
            }
        } else if (nodeConfig.assigneeType == 'self') {
            return "发起人自己"
        }
    },
    conditionStr(conditionNode) {
        if (conditionNode.def) {
            return '来源不符合其它条件时'
        }
        var { conditionList } = conditionNode
        if(!conditionList) return '请设置条件'
        if (conditionList.length == 0) {
            return '请设置条件'
        } else {
            let str = ""
            for (var i = 0; i < conditionList.length; i++) {
                var { columnId, optType, zdy1 } = conditionList[i];
                if (columnId == 0 && zdy1?.length > 0) {
                    if (optType == 1) {
                        str += '发起人属于：'
                        str += zdy1.map(item => store.state.flow.operatorMapping.user[item]).join("或")
                    } else if (optType == 2) {
                        str += '发起人不属于：'
                        str += zdy1.map(item => store.state.flow.operatorMapping.user[item]).join("和")
                    }
                }
                // 目前只考虑发起人,后续根据columnId自行添加
            }
            return str ? str : '请设置条件'
        }
    }
}

export default new All();